package tpase.client.Handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import tpase.client.VO.FileInfo;
import tpase.client.VO.Message;
import tpase.client.VO.StatusCode;
import tpase.util.Util;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ClientDeleteFileHandler extends ChannelInboundHandlerAdapter {

    private final String fid;

    public ClientDeleteFileHandler(String fid) {
        this.fid = fid;
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        Message request = new Message(StatusCode.DELETE_FILE_REQUEST);
        Map<String, byte[]> map = request.getMap();
        map.put("fid", fid.getBytes());

        ctx.writeAndFlush(request);
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        ctx.close();
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        System.out.println("ClientDeleteFileHandler: 发生异常，关闭通道");
        System.out.println(cause.toString());
        ctx.close();
    }
}
